package energy;

public class FlagsProcessorFactory {

	public static DataProcessor getEightStateProcessor() {
		return new EightStateProcessor();
	}
	
	public static DataProcessor getFourStateProcessor() {
		return new FourStateProcessor();
	}
	
	public static DataProcessor getIndependentProcessor() {
		return new IndependentProcessor();
	}
	
	private static class EightStateProcessor extends AbstractDataProcessor {
		public void process(EnergyData data) {
			data.state = (byte)(data.flags & 7);
			data.state++;
		}
		public String getDescription() {
			return "State (1-8)";
		}
	}
	
	// Only 111, 100, 010, 001 is valid	
	private static class FourStateProcessor extends AbstractDataProcessor {
		public void process(EnergyData data) {
			if((data.flags & 7) == 7) {
				data.state = 4;
			} else if ((data.flags & 7) == 4) {
				data.state = 3;
			} else if ((data.flags & 7) == 2) {
				data.state = 2;
			} else if ((data.flags & 7) == 1) {
				data.state = 1;
			} else {
				data.state = 0;
			}
		}
		
		public String getDescription() {
			return "State (1-4)";
		}
	}
	
	private static class IndependentProcessor extends AbstractDataProcessor {
		public void process(EnergyData data) {
			data.state = (byte)(data.flags & 7);
		}
		
		public String getDescription() {
			return "Three Independent Flags";
		}
	}
}
